package com.hzdl.car.mapper;

import com.hzdl.car.bean.User;
import com.hzdl.car.sqlprovider.UserSqlProvider;
import com.hzdl.car.vo.UserVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from sys_user where loginName =#{loginName} and pwd=md5(#{pwd})")
    User login(UserVo userVo);
    @SelectProvider(type = UserSqlProvider.class,method = "findUser")
    List<User> findUser(UserVo userVo);
    @Insert("insert into sys_user (loginName,identity,realName,sex,address,phone,pwd,position,type,available) " +
            "values (#{loginName},#{identity},#{realName},#{sex},#{address},#{phone},MD5(#{pwd}),#{position},#{type},#{available})")
    int addUser(UserVo userVo);
    @Update("update sys_user set loginName=#{loginName},identity=#{identity},realName=#{realName},sex=#{sex}," +
            "address=#{address},phone=#{phone},position=#{position},type=#{type},available=#{available} " +
            "where userId=#{userId}")
    int updateUser(UserVo userVo);
    @Select("select count(*) from sys_role_user where uId=#{userId} ")
    int chkRoleUser(UserVo userVo);
    @Delete("delete from sys_user where userId=#{userId}")
    int delUser(UserVo userVo);
    @Delete("delete from sys_role_user where uId=#{userId}")
    int delRoleUser(UserVo userVo);
    @Update("update sys_user set pwd=MD5(#{pwd}) where userId=#{userId}")
    int resetPwd(UserVo userVo);
    @Delete("delete from sys_role_user where uId=#{id}")
    int deleteRoleByUser(Integer id);
    @Insert("insert into sys_role_user (uId,rId) values (#{uId},#{rId})")
    int addRoleUser(@Param("uId") Integer uId,@Param("rId") Integer rId);
}
